<template>
  <div class="box">
    <div class="content">
      <div class="student">
        <ul v-if="tableData" class="student-info">
          <li>
            <span class="title">宿舍：</span>
            <span class="text">{{ tableData.dormitoryName }}</span>
          </li>
          <li>
            <span class="title">房间名：</span>
            <span class="text">{{ tableData.roomName }}</span>
          </li>
          <li>
            <span class="title">检查人：</span>
            <span class="text">{{ tableData.createUserName }}</span>
          </li>
          <li>
            <span class="title">检查人电话：</span>
            <span v-if="tableData.markUserPhone" class="text">{{ tableData.markUserPhone }}</span>
            <span v-else class="text">--</span>
          </li>
          <li>
            <span class="title">得/扣分：</span>
            <span :class="['text', 'red']">{{ tableData.totalMarkScore }}</span>
          </li>
          <li>
            <span class="title">评分等级：</span>
            <span class="text">{{ tableData.examineGrade }}</span>
          </li>
          <li>
            <span class="title">检查类型：</span>
            <span class="text">{{ tableData.itemSuperiorName }}</span>
          </li>
          <li>
            <span class="title">检查时间：</span>
            <span class="text">{{ tableData.examineTime }}</span>
          </li>
          <li>
            <span class="title">打分时间：</span>
            <span class="text">{{ tableData.createTime }}</span>
          </li>
        </ul>
      </div>

      <div
        v-if="
          tableData.examineType === 3 &&
          tableData.commonExamineList.length === 0 &&
          tableData.studentExamineList.length === 0
        "
        class="deduct-points"
      >
        <div class="no-found">本次打分为快速打分，无打分明细，详情请联系检查人员。</div>
      </div>
      <div v-else>
        <!-- 公共项目打分 -->
        <div v-if="tableData">
          <div v-if="tableData.commonExamineList">
            <div v-if="tableData.commonExamineList.length > 0" class="deduct-points">
              <div class="small-title">公共项目打分</div>
              <div class="deduct-points-content">
                <div class="content-details">
                  <ul class="porject">
                    <li v-for="(item, index) in tableData.commonExamineList" :key="index">
                      <p class="points"
                        >{{ item.markItemName }}
                        <span v-if="tableData.examineType !== 1 && tableData.examineType !== 3">
                          <span v-if="tableData.examineType * 1 !== 1">：</span>
                          <span v-if="tableData.examineType * 1 !== 1">
                            <span v-if="item.score > 0"> + </span>
                          </span>

                          <span v-if="tableData.examineType * 1 !== 1" class="deduct">{{
                            item.score
                          }}</span>
                        </span>
                      </p>
                    </li>
                  </ul>
                </div>
              </div>
            </div>
          </div>
        </div>

        <!-- 个人项目打分 -->
        <div v-if="tableData">
          <div v-if="tableData.studentExamineList">
            <div v-if="tableData.studentExamineList.length > 0" class="deduct-points">
              <div class="small-title">个人项目打分</div>
              <div class="deduct-points-content">
                <div class="content-details">
                  <ul class="personal-porject">
                    <li
                      v-for="(item, index) in tableData.studentExamineList"
                      :key="index"
                      class="personal-info"
                    >
                      <div style="margin: 0 40px 0 0; align-items: center">
                        <span style="margin: 0 16px 0 0">{{ item.studentName }}</span>
                        <span style="margin: 0 16px 0 0">{{ item.bedNum }}号床</span>
                        <span>{{ item.className }}</span>
                      </div>

                      <div>
                        <div
                          v-for="(examine, indexs) in item.examineList"
                          :key="indexs"
                          class="personal-info-li"
                        >
                          <li>
                            <span class="personal-info-content">
                              {{ examine.markItemName }}
                              <span
                                v-if="
                                  tableData.examineType * 1 !== 1 && tableData.examineType !== 3
                                "
                              >
                                ：</span
                              >
                            </span>
                            <span
                              v-if="tableData.examineType * 1 !== 1 && tableData.examineType !== 3"
                              >{{ examine.score > 0 ? '+' + examine.score : examine.score }}</span
                            >
                          </li>
                        </div>
                      </div>
                    </li>
                  </ul>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>

      <!-- 图片 -->
      <div v-if="imgUrlData.length" class="deduct-points">
        <div class="small-title">项目打分图</div>
        <div class="mark">
          <div class="content-img-box">
            <div v-for="item in imgUrlData" :key="item" class="content-img">
              <img :src="item" alt="" />
            </div>
          </div>
        </div>
      </div>

      <!-- 备注 -->
      <!-- <div class="deduct-points">
        <div class="small-title">备注</div>
        <div class="mark">
          <a-textarea v-model:value="tableData.remark" readonly />
        </div>
      </div> -->

      <!-- 操作日志 -->
      <div class="deduct-points">
        <div class="small-title">操作日志</div>
        <div class="operation">
          <div
            v-for="(item, index) in tableData.examineLogList"
            :key="index"
            class="operation-content"
          >
            <div v-if="item.logType === 0" class="operation-content-title"
              >【{{ item.operatorName }}】提交本次打分</div
            >
            <div v-if="item.logType === 1" class="operation-content-title"
              >【{{ item.operatorName }}】重新提交本次打分</div
            >
            <div v-if="item.logType === 2" class="operation-content-title"
              >【{{ item.operatorName }}】删除本次打分</div
            >
            <div>{{ item.createTime }}</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { onMounted, ref, watch } from 'vue';
import { useRouter, useRoute } from 'vue-router';
import { dormitoryDetails } from '@/api/assessment/inspect';
import { message } from 'ant-design-vue';
const router = useRouter();
const route = useRoute();
let examineId = ref([]);
const schoolIdType = ref(0); // 0 是旧版本  1 是新版本 221954838718582784
onMounted(() => {
  // if (localStorage.getItem('localStorageSchoolId') === '346001568933441537'||localStorage.getItem('localStorageSchoolId') === '221954838718582784') {
  //   schoolIdType.value = 1;
  // } else {
  //   schoolIdType.value = 0;
  // }
  examineId.value = router.currentRoute.value.query.examineId; // 宿舍楼
  let obj = {
    examineId: examineId.value
  };
  let bodySty = document.getElementById('myApp');
  bodySty.setAttribute('class', 'bodyStyle');
  getTabsList(obj);
});
watch(
  () => route.matched,
  val => {
    if (!route.query.id) {
      router.push('/check/inspect');
    }
  }
);
const tableData = ref([]);
const imgUrlData = ref([]);
// 获取信息
function getTabsList(obj) {
  dormitoryDetails(obj).then(res => {
    console.log('------------', res.data.code);
    if (res.data.code === 200) {
      tableData.value = res.data.data;
      if (tableData.value.imgUrls) {
        imgUrlData.value = tableData.value.imgUrls.split(',');
      }
    } else {
      message.error(res.data.msg);
      setTimeout(() => {
        router.go(-1);
      }, 300);
    }
  });
}
const mark = ref(null);
</script>

<style lang="less" scoped>
.box {
  background: #f2f2f2;
  // padding: 50px 120px 24px;
  min-height: 100vh;
  min-width: 1300px;
  .content {
    background: #ffffff;
    border-radius: 4px;
    padding: 24px;
    .student {
      border: 1px solid #e4b778;
      border-radius: 4px;
      padding: 24px;
      width: 100%;
      margin-bottom: 24px;
      .student-info {
        display: flex;
        flex-wrap: wrap;
        margin-bottom: 0;
        li {
          width: 20%;
          padding: 12px 0;
          font-size: 14px;
          .title {
            color: #999999;
            display: inline-block;
            width: 40%;
            text-align: end;
          }
          .text {
            color: #222222;
          }
          .red {
            color: #ff0000;
          }
        }
      }
    }
    .deduct-points {
      margin-bottom: 32px;
      &-content {
        padding: 14px 16px;
        background: #f8f8f8;
        border-radius: 4px;
        margin-top: 20px;
        display: flex;
        align-items: center;
      }
      .content-details {
        width: 100%;
        .porject {
          display: flex;
          align-items: center;
          flex-wrap: wrap;
          margin-bottom: 0;
          line-height: 32px;
          li {
            width: 30%;
            font-size: 14px;
            .points {
              color: #999999;
            }
            .deduct {
              color: #222222;
            }
          }
        }
        .personal-porject {
          .personal-info {
            display: flex;
            // align-items: flex-start;
            font-size: 14px;
            font-family: Source Han Sans CN, Source Han Sans CN-Regular;
            color: #222222;
            .personal-info-li {
              display: flex;
              align-items: center;
              font-size: 14px;
              font-family: Source Han Sans CN, Source Han Sans CN-Regular;
              color: #222222;
              .personal-info-content {
                color: #999999;
              }
            }
          }
          .personal-info + .personal-info {
            margin-top: 16px;
          }
          .personal-info::before {
            content: '';
            display: inline-block;
            width: 8px;
            height: 8px;
            background: #bb964b;
            border-radius: 50%;
            margin-right: 8px;
          }
        }
      }
      .content-img-box {
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: flex-start;
        flex-wrap: wrap;
        .content-img {
          width: 86px;
          height: 86px;
          border-radius: 4px;
          background: #f2f2f2;
          margin: 12px;
          overflow: hidden;
          img {
            width: 100%;
            height: 100%;
          }
        }
      }
      .mark,
      .no-found,
      .operation {
        padding: 14px 16px;
        background: #f8f8f8;
        border-radius: 4px;
        margin-top: 20px;
      }
      .no-found {
        text-align: center;
        padding: 32px;
        font-size: 16px;
        font-family: Source Han Sans CN, Source Han Sans CN-Regular;
        color: #666666;
      }
      .operation {
        &-content {
          display: flex;
          align-items: center;
          justify-content: space-between;
          font-size: 16px;
          font-family: Source Han Sans CN, Source Han Sans CN-Regular;
          color: #666666;
          margin: 8px 0;
          &-title::before {
            content: '';
            display: inline-block;
            width: 8px;
            height: 8px;
            background: #999999;
            border-radius: 50%;
            margin-right: 8px;
          }
        }
      }
    }
  }
}
.small-title {
  font-size: 18px;
  font-family: Source Han Sans CN, Source Han Sans CN-Medium;
  font-weight: 500;
  color: #222222;
}
/deep/textarea.micro-dormitory-input {
  border: 0;
  background: transparent;
  resize: none;
}
/deep/.micro-dormitory-input:focus {
  box-shadow: none;
}

.personal-info::before {
  margin-top: 7px;
}
</style>
